package com.calenda.setevent.entity;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONObject;

public class UserEntity {
	// "calendar": [],
	// "mobile": "0904079550",
	// "otp": "off",
	// "fullname": "Đỗ Đức Anh",
	// "sessionid": "",
	// "email": "anhdd@cdit.com.vn",
	// "group": []

	private ArrayList<CalendarEntity> calendarEntities = new ArrayList<CalendarEntity>();
	private ArrayList<GroupEntity> groupEntities = new ArrayList<GroupEntity>();

	private String mobile;
	private String otp;
	private String fullname;
	private String sessionid;
	private String email;
	private JSONObject jsonObject;

	public UserEntity() {
	}

	public UserEntity(JSONObject jsonObject) {
		this.mobile = jsonObject.optString("mobile", "");
		this.otp = jsonObject.optString("otp", "");
		this.fullname = jsonObject.optString("fullname", "");
		this.sessionid = jsonObject.optString("sessionid", "");
		this.email = jsonObject.optString("email", "");

		JSONArray calendar = jsonObject.optJSONArray("calendar");
		if (null != calendar) {
			for (int i = 0; i < calendar.length(); ++i) {
				try {
					JSONObject object = calendar.getJSONObject(i);
					CalendarEntity calendarEntity = new CalendarEntity(object);
					calendarEntities.add(calendarEntity);
				} catch (Exception e) {
					// TODO: handle exception
					e.printStackTrace();
				}
			}
		}

		JSONArray group = jsonObject.optJSONArray("group");
		if (null != group) {
			for (int i = 0; i < group.length(); ++i) {
				try {
					JSONObject object = group.getJSONObject(i);
					GroupEntity groupEntity = new GroupEntity(object);
					groupEntities.add(groupEntity);
				} catch (Exception e) {
					// TODO: handle exception
					e.printStackTrace();
				}

			}
		}

		this.jsonObject = jsonObject;
	}

	public UserEntity(ArrayList<CalendarEntity> calendarEntities,
			ArrayList<GroupEntity> groupEntities, String mobile, String otp,
			String fullname, String sessionid, String email) {
		this.calendarEntities = calendarEntities;
		this.groupEntities = groupEntities;
		this.mobile = mobile;
		this.otp = otp;
		this.fullname = fullname;
		this.sessionid = sessionid;
		this.email = email;
	}

	public ArrayList<CalendarEntity> getCalendarEntities() {
		return calendarEntities;
	}

	public void setCalendarEntities(ArrayList<CalendarEntity> calendarEntities) {
		this.calendarEntities = calendarEntities;
	}

	public ArrayList<GroupEntity> getGroupEntities() {
		return groupEntities;
	}

	public void setGroupEntities(ArrayList<GroupEntity> groupEntities) {
		this.groupEntities = groupEntities;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getOtp() {
		return otp;
	}

	public void setOtp(String otp) {
		this.otp = otp;
	}

	public String getFullname() {
		return fullname;
	}

	public void setFullname(String fullname) {
		this.fullname = fullname;
	}

	public String getSessionid() {
		return sessionid;
	}

	public void setSessionid(String sessionid) {
		this.sessionid = sessionid;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public JSONObject toJson() {
		return jsonObject;
	}

	@Override
	public String toString() {
		return "UserEntity [calendarEntities=" + calendarEntities
				+ ", groupEntities=" + groupEntities + ", mobile=" + mobile
				+ ", otp=" + otp + ", fullname=" + fullname + ", sessionid="
				+ sessionid + ", email=" + email + "]";
	}
}
